home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2962 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: SOCKETS
  5. Date: 20 Jan 1996 23:15:24 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4drt2c$ig9@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe11.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 20, 1996 18:57:12 in article <SOCKETS>,
  15. 'M.J.Thomsit-CSSE93@cs.bham.ac.uk (Mark J Thomsit)' wrote: 
  16.  
  17.  
  18. >Is there a way to check if a socket is holding any data, without having to
  19.  
  20. >wait 
  21. >until some data appears, ? 
  22. You didn't specify the platform.  If using raw BSD4.3 sockets on Unix,  
  23. it's done by setting the socket options with the fcntl() system call: 
  24.  
  25.    fcntl(fd, F_SETFL, FNDELAY); 
  26.  
  27. This makes your socket non-blocking.  When you attempt to read 
  28. from this socket, say by using the recv() system call, and it returns 
  29. 0, you can verify that no data is available by checking the global 
  30. errno variable for the value EWOULDBLOCK. 
  31.  
  32. With System V TLI, non-blocking IO is accomplished by specifying 
  33. the O_NDELAY flag when opening the stream with t_open. 
  34.  
  35. In Winsock, you really should use asynchronous sockets where 
  36. your program is notified whenever data 'comes in'.  See docs 
  37. on WSAAsyncSelect function. 
  38. -- 
  39. Pete Grant 
  40. Kalevi, Inc. 
  41. Object Oriented Software Development
  42.